package su.NewFeatureType;

import su.Ner.NerDataSequence;
import iitb.CRF.DataSequence;
import iitb.Model.FeatureGenImpl;
import iitb.Model.FeatureImpl;
import iitb.Model.FeatureTypes;

public class PersonDictFeatures extends FeatureTypes {

	int stateId;
	int seat;
    Object fname= "PD.";
    public int maxFeatureNum=NerDataSequence.labelNum;
    
	
	public PersonDictFeatures(FeatureGenImpl fgen,int baseId) {
		super(fgen);
		this.baseId=baseId;
	}

	@Override
	public boolean hasNext() {
		if (stateId==-1)
			return false;
		return true;
	}

	@Override
	public void next(FeatureImpl f) {
		//setFeatureIdentifier(baseId-(seat*NerDataSequence.labelNum+stateId),stateId,fname,f);
		f.strId.init(baseId-stateId, stateId, fname);
		
		f.yend = stateId;
		f.ystart = -1;
		f.val = 1;
		stateId++;
		if(stateId==NerDataSequence.labelNum)
			stateId=-1;
	}

	@Override
	public boolean startScanFeaturesAt(DataSequence data, int prevPos, int pos) {
		
		_data=data;
		_pos=pos;
		
		int t=data.y(pos);
		String word=(String)data.x(pos);
		word=word.toLowerCase();
		if(word.length()<2 ) {
			stateId=-1;
			return false;
		}
		
		Integer i=this.fgen.names.personNames.get(word);
		if(null!=i)
			seat=i;
		else{
			stateId=-1;
			return false;
		}
		stateId=0;
		return true;
	}
	
	DataSequence _data;
	int _pos;
	
}
